Improve diagnostics for multiple native links for the same package
authorManish Goregaokar <manishsmail@gmail.com>
Fri, 20 Nov 2015 16:11:05 +0000 (21:41 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Fri, 20 Nov 2015 17:29:05 +0000 (22:59 +0530)
src/cargo/ops/cargo_rustc/links.rs

index 8f152d76c455505e33d1f1d3dd8726a4da61e6db..2021ffd75090a6e68b7513068e8562902e2192df 100644 (file)
@@ -1,12 +1,12 @@
 use std::collections::HashMap;
 
-use core::PackageSet;
+use core::{PackageId, PackageSet};
 use util::{CargoResult, human};
 
 // Validate that there are no duplicated native libraries among packages and
 // that all packages with `links` also have a build script.
 pub fn validate(deps: &PackageSet) -> CargoResult<()> {
-    let mut map = HashMap::new();
+    let mut map: HashMap<_, &PackageId> = HashMap::new();
 
     for dep in deps.iter() {
         let lib = match dep.manifest().links() {
@@ -15,11 +15,25 @@ pub fn validate(deps: &PackageSet) -> CargoResult<()> {
         };
         match map.get(&lib) {
             Some(previous) => {
-                return Err(human(format!("native library `{}` is being linked \
-                                          to by more than one package, and \
-                                          can only be linked to by one \
-                                          package\n\n  {}\n  {}",
-                                         lib, previous, dep.package_id())))
+                let depid = dep.package_id();
+                if previous.name() == depid.name()
+                    && previous.source_id() == depid.source_id() {
+                    return Err(human(format!("native library `{}` is being \
+                                              linked to by more than one \
+                                              version of the same package, but \
+                                              it can only be linked \
+                                              once; try updating \
+                                              or pinning your dependencies to \
+                                              ensure that this package only \
+                                              shows up once\n\n  {}\n  {}",
+                                             lib, previous, dep.package_id())))
+                } else {
+                    return Err(human(format!("native library `{}` is being \
+                                              linked to by more than one \
+                                              package, and can only be linked \
+                                              to by one package\n\n  {}\n  {}",
+                                             lib, previous, dep.package_id())))
+                }
             }
             None => {}
         }